* ======================================
* ------------ Split Family ------------
* ======================================


	use $dta\EstimationSample.dta, clear


* Import relations
*=================

	rename Voter_id idPers	
	rename Fam2Pol_id idFam2
	merge m:1 idPers idFam2 using $dta\NetworkFam2.dta, nogen ///
		keep(master matched) // extended subsumes close
	rename Family FamPol_fam
	rename idFam2 FamPol_id
	rename idPers Voter_id

	forvalues i = 1/8{
		gen fam`i'Any = 1*(Fam2Any == 1 & FamPol_fam == `i')
		gen fam`i'Same = 1*(Fam2Same == 1 & FamPol_fam == `i')
	}


* Estimate models
* ===============

	egen idbsu = group(Voter_id Voter_bsu)
	gen period = 1*(year == 2019)
	xtset idbsu period
	estimates clear


	forvalues i = 1/8{
	
		preserve
		sum Voter_turnout 	// mean depvar
		local meandepvar = string(r(mean)*100, "%15.2fc")

		gen Any = fam`i'Any
		gen Same = fam`i'Same
		eststo m_`i': xtreg Voter_turnout Any Same i.period, ///
			i(idbsu) fe cluster(Voter_bsu)
		quietly estadd local meandep `meandepvar', replace
		restore
	}



* Export table
* ============

	esttab m_* ///
		using $tbls\SplitFamily.tex, replace  style(tex) ///
		prehead("\begin{tabular}{l*{9}{c}} \hline\hline \\ ") ///
		posthead("\hline \\") ///
		fragment ///
		mtitles("Parents" "Siblings" "Children" "Grandpar." "Grandch." ///
			"\shortstack{Nieces \& \\ nephews}" ///
			"\shortstack{Aunts \& \\ uncles}" "Cousins") ///
		label se b(%9.3f) se(%9.3f) nostar ///
		refcat(Any "\shortstack{ No network candidate }") ///
		coeflabels(Any "Any District" Same "Same District" ) ///
		drop(_cons *.period ) noomitted nobaselevels ///
		nonotes stats(N N_clust meandep, labels( ///
			"Observations" "Clusters" "Mean turnout (\%)") ///
			fmt(%15.0fc %15.0fc %15.0fc)) substitute(\_ _) ///
		prefoot("\hline") ///
		postfoot("\hline\hline \\ \end{tabular}")